package performance;

/**
 * JDK8中是一个伪命题，已近优化过；JDK8以下需要确认
 * Created by juntao zhang on 19/10/2016.
 */
public class 提取表达式优化 {
    public static void main(String[] args) {
        double d = Math.random();
        double a = Math.random();
        double b = Math.random();
        double e = Math.random();
        double f = Math.random();
        double x, y, tmp;
        Long start = System.currentTimeMillis();
        for (long i = 0; i < 10000000000L; i++) {
            x = d * a * b / 3 * 4 * a / f;
            y = e * a * b / 3 * 4 * a / f;
        }
        System.out.println("cost " + (System.currentTimeMillis() - start) + " ms");
        System.out.println("====优化之后====");
        start = System.currentTimeMillis();
        for (long i = 0; i < 10000000000L; i++) {
            tmp = a * b / 3 * 4 * a / f;
            x = d * tmp;
            y = e * tmp;
        }
        System.out.println("cost " + (System.currentTimeMillis() - start) + " ms");
    }
}
